<template>
  <div>
    <el-form inline :model="queryData" ref="queryData" class="query-form">
      <el-form-item label="园区名称:" prop="gardenName">
        <el-input v-model="queryData.gardenName" placeholder="请输入" style="width: 200px" clearable
                  @clear="formClear('name')"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查 询</el-button>
        <el-button @click="onReset">重 置</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableList" border style="width: 100%;">
      <el-table-column type="index" label="序号" align="center"/>
      <el-table-column prop="gardenName" label="园区名称" align="center" show-overflow-tooltip/>
      <el-table-column prop="region" label="省市区" align="center"/>
      <el-table-column prop="manageName" label="申请人" align="center"/>
      <el-table-column prop="wxPhone" label="联系电话" align="center"/>
      <el-table-column prop="checkStatusString" label="审核状态" align="center"/>
      <el-table-column label="操作" align="center" width="150">
        <template slot-scope="{row}">
          <el-dropdown trigger="click" @command="checkStatusEvent($event, row)" v-if="row.checkStatus !=0">
            <div class="el-dropdown-link">
              <span>{{row.checkStatusString}}</span>
              <i class="el-icon-arrow-down el-icon--right"></i>
            </div>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="0">审核通过</el-dropdown-item>
              <el-dropdown-item command="2">拒绝审核</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <Paging v-model="queryData" @change="getRequest"></Paging>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'

  export default {
    computed: {
      ...mapGetters(['confirm'])
    },
    name: 'parkList',
    data() {
      return {
        tableList: [],
        queryData: {
          pageNum: 1,
          pageSize: 10,
          total: 0
        }
      }
    },

    beforeMount() {
      this.getRequest()
    },
    methods: {
      checkStatusEvent(event, row) {
        console.log(event, row)
        if (event == 0) {
          this.$confirm('此操作将无法修改, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(async () => {
            await this.$ajax.post('/wx/garden/certificationApplication/updateCheck', {
              checkStatus: event,
              id: row.id
            })
            this.$message.success('操作成功')
            this.getRequest()
          })
        } else if(event == 2) {
          this.$prompt('请输入拒绝理由', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
          }).then(async ({ value }) => {
            if (!value) return this.$message.warning('请输入拒绝理由')
            await this.$ajax.post('/wx/garden/certificationApplication/updateCheck', {
              reject: value,
              checkStatus: event,
              id: row.id
            })
            this.$message.success('操作成功')
            this.getRequest()
          })
        }
      },
      /**
       * 重置事件
       */
      onReset() {
        this.$refs['queryData'].resetFields()
        this.getRequest()
      },
      /**
       * 查询条件提交事件
       */
      onSubmit() {
        this.queryData.pageNum = 1
        this.getRequest()
      },
      /**
       * 列表请求事件
       */
      async getRequest() {
        const formData = JSON.parse(JSON.stringify(this.queryData))
        const res = await this.$ajax.get('/wx/garden/certificationApplication/checkList', { params: formData })
        this.queryData.total = res.total
        this.tableList = res.rows
      },
      /**
       * form置空事件
       */
      formClear(key) {
        this.queryData[key] = null
        this.onSubmit()
      }
    }
  }
</script>

<style scoped>

</style>
